import tornado.web
import tornado.ioloop
import tornado.httpclient
from . import utils
import json
import threading
'''
#4 文本意图识别
    http://ip:port/txt/tic
    {
        "text":"",
        "id":""
    }

'''
class txtTic(tornado.web.RequestHandler):


    def post(self, *args, **kwargs):
        resp = None
        try:
            data=json.loads(self.request.body)
            print(data)
            paramerror = utils.checkParam(data, {
                "text":"",
                "id":""
            })
            if paramerror == '':
                resp = {
                    "result":[
                        {
                            "label":"sf",
                            "score":"0.602000"
                        },
                        {
                            "label":"null",
                            "score":"0.398000"
                        }
                    ],
                    "id":data['id'],
                    "state":{
                        "ok":1,
                        "failed":''
                    }

                }
            else:
                resp = {
                    "result":"",
                    "state":{
                        "ok":0,"failed": paramerror
                    }
                }

        except BaseException as e:
            resp = {
                "result":"",
                "state":{
                    "ok":0,"failed": str(e)
                }
            }

        self.write(resp)
